<?php
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2002-2005 Fr&eacute;d&eacute;ric Descamps <lefred@tiscali.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
include_once("includes/db.inc");
include_once("includes/functions.inc");

session_start();
include_once("includes/session.inc");

ControleAcces("histobook.php",$login,$pwd,$user_id,session_id());

if(!$user_id)
{
 exit;
}

$result = biblio_db_query("SELECT login FROM admin WHERE id = $user_id" ,$db);
$myrow = biblio_db_fetch_array($result);
$user = $myrow['login'] ;

include ("includes/header.inc");
if ($user)
{
$id=$_GET['id'];
if(!$id)
{
        include("includes/search2.inc");
}
else
{
        echo "<CENTER><H3>";
	echo _("Voici l'historique du livre");
	echo ": <i>$nom</i></H3>";
        $requete = "SELECT t1.date_out, t1.date_int, t3.etat etat_out, t6.etat etat_in, t1.id id_to, t4.nom nom_el, t4.prenom prenom_el FROM prets as t1 inner join etats as t3 on t3.id = t1.etat_out_ID left join etats as t6 on t6.id = t1.etat_in_ID inner join eleves as t4 on t4.id = t1.eleve_ID where t1.livre_id = $id  order by date_out"; 
        put_log(7,$nom,$user);   
         if(!($resultat2 = biblio_db_query($requete)))
	 { print _("PROBLEME") ." $requete: " .biblio_db_error(); }
	 else 
 	 {  
	        $i=0;	        
	        echo "<TABLE><tr><th>";
		echo _("Titre");
		echo "</th><th>";
		echo _("Date de sortie");
		echo "</th><th>";
		echo _("Date de retour");
		echo "</th><th>";
		echo _("Nb. Jours<BR>emprunt&eacute;");
		echo "</th><th>";
		echo _("El&egrave;ve");
		echo "</th><th>";
		echo _("Etat Sortant");
		echo "</th><th>";
		echo _("Etat Entrant");
		echo "</th></tr>";
	        while ($myrow = biblio_db_fetch_array($resultat2)) 
	        {
		       $tab_mois = array('',_('janvier'),_('f&eacute;vrier'),_('mars'),_('avril'),_('mai'),_('juin'),_('juillet'),
		       	_('ao&ucirc;t'),_('septembre'),_('octobre'),_('novembre'),_('decembre'));
	               $date_sort = $myrow['date_out'];
		       $date_start = $date_sort;
	               ereg("(....)-(..)-(..)$",$date_sort,$match);
	               $jour  = $match[3];
	               $mois  = sprintf("%d",$match[2]);
	               $annee = $match[1];
	               $date_sort =  "$jour " . $tab_mois[$mois] . " $annee";
     		       $date_ent = $myrow['date_int'];
		       if ($date_ent == "") 
		       {
                        	$date_ent = _("Toujours en pr&ecirc;t");
				$date_end =  date("Y-m-d");
			} 
 	               else 
 		       {	                                      
			   $date_end =  $date_ent;
	         	   ereg("(....)-(..)-(..)$",$date_ent,$match);
	          	   $jour  = $match[3];
	           	   $mois  = sprintf("%d",$match[2]);
	            	   $annee = $match[1];
		       	   $date_ent = "$jour " . $tab_mois[$mois] . " $annee";			
              		}   
                       $elementsdate = explode("-",$date_start);
                       $date_start = mktime(0,0,0,$elementsdate[1],$elementsdate[2],$elementsdate[0]);
		       $elementsdate = explode("-",$date_end);
                       $date_end = mktime(0,0,0,$elementsdate[1],$elementsdate[2],$elementsdate[0]);
                       $total_jour = $date_end - $date_start;
 		       $total_jour = $total_jour/86400;
		       $etat_out = $myrow['etat_out'];
		       $etat_in = $myrow['etat_in'];
	               $id_to = $myrow['id_to'];
	               $livre_titre = $_GET['nom'];
		       $eleve = $myrow['prenom_el'] . " " . $myrow['nom_el'];
	              
	               $i++;
	               if ($i%2 == 1) {$col="#DFE3EF";}
	               else {$col="lightyellow";}
                       echo "<TR bgcolor=$col><TD> $livre_titre</TD><TD>$date_sort</TD><TD>$date_ent</TD><TD ALIGN=RIGHT>$total_jour</TD><TD> $eleve</TD><TD>$etat_out</TD><TD>$etat_in</TD><tr>";
                }
		echo "</TABLE></center>";
         }              	   
} 
}
?>
<br><br>
<div>
<span id=left-text>
<A HREF="admin.php?menu=1">
<?php echo _("retour menu administration"); ?>
</A><BR>
<A HREF="index.php">
<?php echo _("retour menu principal"); ?>
</A></span>
</div>
<br>
<?php
include("includes/footer.inc");
?>
